package cc.yugu.yhdw.webserver.web.controller.security.hdw;

import cc.yugu.yhdw.common.annotation.ViewModel;
import cc.yugu.yhdw.common.domain.hdw.AgencyDeductMoney;
import cc.yugu.yhdw.common.entity.json.ExtResult;
import cc.yugu.yhdw.common.entity.json.PageResult;
import cc.yugu.yhdw.webserver.service.hdw.AgencyDeductMoneyService;
import cc.yugu.yhdw.webserver.web.controller.security.SecurityController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/security/hdw/agency_deduct_money")
public class AgencyDeductMoneyController extends SecurityController {

    @Autowired
    AgencyDeductMoneyService agencyDeductMoneyService;

    @RequestMapping("page.htm")
    @ViewModel(ViewModel.JSON)
    @ResponseBody
    public PageResult page(AgencyDeductMoney search) {
        return PageResult.successResult(agencyDeductMoneyService.findPage(search));
    }

    @RequestMapping("add.htm")
    @ViewModel(ViewModel.INNER_PAGE)
    public void add(int agencyId, Model model) {
        model.addAttribute("agencyId", agencyId);
    }

    @RequestMapping("create.htm")
    @ViewModel(ViewModel.JSON)
    @ResponseBody
    public ExtResult create(AgencyDeductMoney entity) {
        return agencyDeductMoneyService.insert(entity);
    }


    @RequestMapping("edit.htm")
    @ViewModel(ViewModel.INNER_PAGE)
    public String edit(int id, Model model) {
        AgencyDeductMoney record = agencyDeductMoneyService.find(id);
        if (record == null) {
            return SEGMENT_RECORD_NOT_FOUND;
        }
        model.addAttribute("entity", record);
        return "/security/hdw/agency_deduct_money/edit";
    }

    @RequestMapping("update.htm")
    @ViewModel(ViewModel.JSON)
    @ResponseBody
    public ExtResult update(AgencyDeductMoney entity) {
        return agencyDeductMoneyService.update(entity);
    }

    @RequestMapping("delete.htm")
    @ViewModel(ViewModel.JSON)
    @ResponseBody
    public ExtResult delete(int id) {
        return agencyDeductMoneyService.delete(id);
    }
}
